package cn.ibizlab.odoo.core.odoo_account.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iaccount_reconciliation_widget;
import cn.ibizlab.odoo.core.odoo_account.domain.Account_reconciliation_widget;
import cn.ibizlab.odoo.core.odoo_account.filter.Account_reconciliation_widgetSearchContext;
import cn.ibizlab.odoo.core.odoo_account.service.IAccount_reconciliation_widgetService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[会计核销挂账] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Account_reconciliation_widgetServiceImpl implements IAccount_reconciliation_widgetService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iaccount_reconciliation_widgetClientService account_reconciliation_widgetClientService;

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iaccount_reconciliation_widget clientModel = account_reconciliation_widgetClientService.createModel();
        clientModel.setId(id);
        account_reconciliation_widgetClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void createBatch(List<Account_reconciliation_widget> account_reconciliation_widgets, int batchSize) {

                        //account_reconciliation_widgetClientService.createBatch(account_reconciliation_widgets,batchSize) ;

    }

    @Override
    public boolean create(Account_reconciliation_widget account_reconciliation_widget) {
        boolean bOk = false ;
        Iaccount_reconciliation_widget clientModel = this.convert2Model(account_reconciliation_widget,null);
        account_reconciliation_widgetClientService.create(clientModel) ;
        this.convert2Domain(clientModel,account_reconciliation_widget);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //account_reconciliation_widgetClientService.removeBatch(account_reconciliation_widgets) ;

    }

    @Override
    public boolean update(Account_reconciliation_widget account_reconciliation_widget) {
        boolean bOk = false ;
        Iaccount_reconciliation_widget clientModel = this.convert2Model(account_reconciliation_widget,null);
        account_reconciliation_widgetClientService.update(clientModel) ;
        this.convert2Domain(clientModel,account_reconciliation_widget) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Account_reconciliation_widget get(Integer id) {
        Iaccount_reconciliation_widget clientModel = account_reconciliation_widgetClientService.createModel();
        clientModel.setId(id);
        account_reconciliation_widgetClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Account_reconciliation_widget get(Account_reconciliation_widget account_reconciliation_widget) {
        Account_reconciliation_widget retaccount_reconciliation_widget = this.get(account_reconciliation_widget.getId()) ;
    	BeanCopier copier=BeanCopier.create(retaccount_reconciliation_widget.getClass(), account_reconciliation_widget.getClass(), false);
        copier.copy(retaccount_reconciliation_widget, account_reconciliation_widget, null);
        return account_reconciliation_widget ;
    }

    @Override
    public void updateBatch(List<Account_reconciliation_widget> account_reconciliation_widgets, int batchSize) {

        //account_reconciliation_widgetClientService.updateBatch(account_reconciliation_widgets,batchSize) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Account_reconciliation_widget> searchDefault(Account_reconciliation_widgetSearchContext context) {
        List<Account_reconciliation_widget> list = new ArrayList<Account_reconciliation_widget>();
        Page<cn.ibizlab.odoo.core.client.model.Iaccount_reconciliation_widget> clientModelList = account_reconciliation_widgetClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iaccount_reconciliation_widget clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Account_reconciliation_widget>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Iaccount_reconciliation_widget convert2Model(Account_reconciliation_widget domain , Iaccount_reconciliation_widget model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = account_reconciliation_widgetClientService.createModel() ;
        }

         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
        return model ;
    }

    public Account_reconciliation_widget convert2Domain( Iaccount_reconciliation_widget model ,Account_reconciliation_widget domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Account_reconciliation_widget();
        }

        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        return domain ;
    }


}
